package middleware

import (
	"net/http"
	"time"
	"log"
)

//LogMiddleware 日志中间件
type LogMiddleware struct {
	next http.Handler
}

func (lm *LogMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	start := time.Now()
	log.Printf("接收到请求 Method: %s  Path:%s", r.Method, r.URL.Path)
	lm.next.ServeHTTP(w, r)
	log.Printf("请求完成 Path: %s 花费时间：%v", r.URL.Path, time.Since(start))
}

func NewLogMiddleware(handler http.Handler)*LogMiddleware{
	return &LogMiddleware{next:handler}
}



